% This file creates Figure 2 and saves it as Figure_2 in
% Replication_files\Figures.

cd ../m_files
set_parameters(2.48,0,1.51,-0.52,0.8,15,1,0,8);

cd ../mod_files
dynare a15_markups.mod
corr_w_inertia=zeros(1,17);
for i=-8:1:8
    corr_w_inertia(i+9)=corr(mu(9+i:9992+i),y(9:9992));
end

cd ../mat_files
save('tfp_corr_model.mat','corr_w_inertia');

cd ../m_files
set_parameters(0,0,1.51,-0.52,0.8,15,1,0,8);

cd ../mod_files
dynare a15_markups.mod
corr_wo_inertia=zeros(1,17);
for i=-8:1:8
    corr_wo_inertia(i+9)=corr(mu(9+i:9992+i),y(9:9992));
end

cd ../mat_files
save('tfp_corr_model.mat','corr_wo_inertia','-append');

%% Clear, load and plot 

clear;
load('tfp_corr_model.mat')
load('nr2020_tfp_corrs.mat')

fig2=figure;
box('on');
hold on

plot(-8:8,corrs(:,3),'-.k','LineWidth',1);
plot(-8:8,corr_w_inertia,'k-*','LineWidth',1);
plot(-8:8,corr_wo_inertia,'k--o','LineWidth',1);
plot(-8:8,zeros(1,17),'--k','LineWidth',0.5);

ylim([-0.7,0.5]);

y1=get(gca,'ylim');
plot([0 0],y1,'--k','LineWidth',0.5);
legend({'Nekarda and Ramey (2020)','Model with Inertia', ...
        'Model without Inertia'},'FontSize',11,'FontWeight','normal')  


xlabel('Lead/Lag of Markup','FontSize',11,'FontWeight','normal');
ylabel('Correlation with Output','FontSize',11,'FontWeight','normal');

fig2.PaperUnits='inches';
fig2.PaperPosition=[0 0 9 5];

cd ../Figures
print('Figure_2','-depsc','-tiff')
cd ../m_files